package org.cid54.bukkit.command;

import org.cid54.bukkit.command.util.PlayerCommand;
import org.bukkit.Material;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.inventory.ItemStack;
import org.cid54.bukkit.Cid54PlayerListener;

/**
 *
 * @author Cid54
 */
public class EquipCommand implements PlayerCommand {

    public boolean execute(String command, PlayerChatEvent event, Cid54PlayerListener listener) {

        String[] commands = command.split(" ");

        String material = "chainmail";

        if (commands.length > 1) {
            material = commands[1].toLowerCase();
        }

        if (material.equals("chainmail")) {

            event.getPlayer().getInventory().setBoots(new ItemStack(Material.CHAINMAIL_BOOTS));
            event.getPlayer().getInventory().setChestplate(new ItemStack(Material.CHAINMAIL_CHESTPLATE));
            event.getPlayer().getInventory().setHelmet(new ItemStack(Material.CHAINMAIL_HELMET));
            event.getPlayer().getInventory().setLeggings(new ItemStack(Material.CHAINMAIL_LEGGINGS));

            event.getPlayer().chat("!give " + Material.DIAMOND_PICKAXE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_AXE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_SPADE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_SWORD.getId());

        } else if (material.equals("diamond")) {

            event.getPlayer().getInventory().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
            event.getPlayer().getInventory().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
            event.getPlayer().getInventory().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
            event.getPlayer().getInventory().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));

            event.getPlayer().chat("!give " + Material.DIAMOND_PICKAXE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_AXE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_SPADE.getId());
            event.getPlayer().chat("!give " + Material.DIAMOND_SWORD.getId());

        } else if (material.equals("gold")) {

            event.getPlayer().getInventory().setBoots(new ItemStack(Material.GOLD_BOOTS));
            event.getPlayer().getInventory().setChestplate(new ItemStack(Material.GOLD_CHESTPLATE));
            event.getPlayer().getInventory().setHelmet(new ItemStack(Material.GOLD_HELMET));
            event.getPlayer().getInventory().setLeggings(new ItemStack(Material.GOLD_LEGGINGS));

            event.getPlayer().chat("!give " + Material.GOLD_PICKAXE.getId());
            event.getPlayer().chat("!give " + Material.GOLD_AXE.getId());
            event.getPlayer().chat("!give " + Material.GOLD_SPADE.getId());
            event.getPlayer().chat("!give " + Material.GOLD_SWORD.getId());

        } else if (material.equals("iron")) {

            event.getPlayer().getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));
            event.getPlayer().getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
            event.getPlayer().getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
            event.getPlayer().getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));

            event.getPlayer().chat("!give " + Material.IRON_PICKAXE.getId());
            event.getPlayer().chat("!give " + Material.IRON_AXE.getId());
            event.getPlayer().chat("!give " + Material.IRON_SPADE.getId());
            event.getPlayer().chat("!give " + Material.IRON_SWORD.getId());

        }

        event.getPlayer().chat("!give " + Material.GOLD_HOE.getId() + " 1");

        event.getPlayer().setHealth(20);

        return true;

    }

    public String getCommand() {
        return "equip";
    }

    public String getHelpText() {
        return "equip chainmail|gold|diamond|iron";
    }
}
